<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'项目列表'),
	array('op'=>'edit','title'=>'添加项目'),	
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','paixu','uniacid','mid','cid','desc_placeholder','status','title_placeholder','ishospitalname','ishospital','isshenfen','faname','shouname','bank_id','bank_name','fa_relation','title','image','starttime','jtimes','ztimes','is_shenhe','is_p','goalmoney','getmoney','status','desc','shuoming','jincheng','shouchishenfenz','hospitalz','createtime');
	$list=pdo_getslice('jy_zhongchou_project',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$classify=pdo_get('jy_zhongchou_classify',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['cid']));
			$item['cname']=$classify['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'image','title'=>'项目封面','type'=>'image'),
			array('name'=>'cname','title'=>'所属分类','type'=>'string'),
			array('name'=>'faname','title'=>'发起人姓名','type'=>'string'),
			array('name'=>'shouname','title'=>'受助人姓名','type'=>'string'),
			array('name'=>'fa_relation','title'=>'关系','type'=>'string'),
			array('name'=>'goalmoney','title'=>'目标金额','type'=>'string'),
			array('name'=>'getmoney','title'=>'已筹金额','type'=>'string'),
			array('name'=>'starttime','title'=>'开始时间','type'=>'string'),
			array('name'=>'is_p','title'=>'是否推荐','type'=>'switch','set'=>'set'),
			array('name'=>'status','title'=>'项目状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'项目名称','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['status']=array('开启','关闭');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='shenhe'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['is_shenhe']=0;
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','paixu','uniacid','mid','cid','desc_placeholder','status','title_placeholder','ishospitalname','ishospital','isshenfen','faname','phone','shouname','bank_id','bank_name','fa_relation','title','image','starttime','jtimes','ztimes','is_shenhe','is_p','goalmoney','getmoney','status','desc','shuoming','jincheng','shouchishenfenz','hospitalz','createtime');
	$list=pdo_getslice('jy_zhongchou_project',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$classify=pdo_get('jy_zhongchou_classify',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['cid']));
			$item['cname']=$classify['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'image','title'=>'项目封面','type'=>'image'),
			array('name'=>'cname','title'=>'所属分类','type'=>'string'),
			array('name'=>'faname','title'=>'发起人姓名','type'=>'string'),
			array('name'=>'phone','title'=>'发起人电话','type'=>'string'),
			array('name'=>'bank_id','title'=>'收款银行卡卡号','type'=>'string'),
			array('name'=>'bank_name','title'=>'银行名称','type'=>'string'),
			array('name'=>'shouname','title'=>'受助人姓名','type'=>'string'),
			array('name'=>'fa_relation','title'=>'关系','type'=>'string'),
			array('name'=>'goalmoney','title'=>'目标金额','type'=>'string'),
			array('name'=>'getmoney','title'=>'已筹金额','type'=>'string'),
			array('name'=>'starttime','title'=>'开始时间','type'=>'string'),
			array('name'=>'is_p','title'=>'是否推荐','type'=>'switch','set'=>'set'),
			array('name'=>'status','title'=>'项目状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'项目名称','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['status']=array('开启','关闭');
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_zhongchou_project',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));

	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['item']['shouchishenfenz']=json_decode($item['shouchishenfenz'],true);
	$return['item']['hospitalz']=json_decode($item['hospitalz'],true);
	$return['item']['buchong']=json_decode($item['buchong'],true);
	$return['item']['cailiao']=json_decode($item['cailiao'],true);
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回项目列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'title','title'=>'项目名称','type'=>'string'),
					array('name'=>'paixu','title'=>'排序','type'=>'string'),
					array('name'=>'image','title'=>'项目封面','type'=>'image'),
					array('name'=>'cid','title'=>'所属分类','type'=>'select','options'=>'cid'),
					array('name'=>'mid','title'=>'发起人会员账号','type'=>'choose','action'=>'get_member','choose_title'=>'选择会员'),
					array('name'=>'faname','title'=>'发起人姓名','type'=>'string'),
					array('name'=>'phone','title'=>'发起人电话','type'=>'string'),
					array('name'=>'bank_id','title'=>'收款银行卡卡号','type'=>'string'),
					array('name'=>'bank_name','title'=>'银行名称','type'=>'string'),
			        array('name'=>'shouname','title'=>'受助人姓名','type'=>'string'),
			        array('name'=>'fa_relation','title'=>'关系','type'=>'string'),
					array('name'=>'goalmoney','title'=>'目标金额','type'=>'string'),
					array('name'=>'is_p','title'=>'是否推荐','type'=>'switch'),
					array('name'=>'desc_placeholder','title'=>'详情标题','type'=>'string'),
					array('name'=>'cailiao','title'=>'材料','type'=>'images'),
					//array('name'=>'shouchishenfenz','title'=>'手持身份证','type'=>'images'),
					//array('name'=>'hospitalz','title'=>'医疗说明','type'=>'images'),
					//array('name'=>'buchong','title'=>'补充材料','type'=>'images'),
					array('name'=>'desc','title'=>'详情','type'=>'richtext'),
					array('name'=>'shuoming','title'=>'说明','type'=>'richtext'),
					array('name'=>'is_shenhe','title'=>'审核是否通过','type'=>'switch'),
					array('name'=>'status','title'=>'是否结束项目','type'=>'switch'),
				)
			),
		)
	);
	$return['cid']=pdo_getall('jy_zhongchou_classify',array('uniacid'=>$_SESSION['uniacid'],'is_show'=>1),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写项目名称','error');
	}
	if(!$postdata['image']){
		exi('请填写项目封面','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'image'=>trim($postdata['image']),
		//'starttime'=>trim($postdata['starttime']),
		'paixu'=>intval($postdata['paixu']),
		'is_p'=>intval($postdata['is_p']),
		'mid'=>intval($postdata['mid']),
		'cid'=>intval($postdata['cid']),
		'goalmoney'=>intval($postdata['goalmoney']),
		'is_shenhe'=>intval($postdata['is_shenhe']),
		'faname'=>trim($postdata['faname']),
		'shouname'=>trim($postdata['shouname']),
		'phone'=>trim($postdata['phone']),
		'bank_id'=>trim($postdata['bank_id']),
		'bank_name'=>trim($postdata['bank_name']),
		'fa_relation'=>trim($postdata['fa_relation']),
		'desc_placeholder'=>trim($postdata['desc_placeholder']),
		'shouchishenfenz'=>ijson_encode($postdata['shouchishenfenz']),
		'hospitalz'=>ijson_encode($postdata['hospitalz']),
		'buchong'=>ijson_encode($postdata['buchong']),
		'cailiao'=>ijson_encode($postdata['cailiao']),
		'desc'=>trim($postdata['desc']),
		'shuoming'=>trim($postdata['shuoming']),
		'status'=>intval($postdata['status']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_zhongchou_project',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_zhongchou_project',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_zhongchou_project',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的项目！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_zhongchou_project',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['is_p'])){
		pdo_update('jy_zhongchou_project',array('is_p'=>intval($post['is_p'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['is_shenhe'])){
		pdo_update('jy_zhongchou_project',array('is_shenhe'=>intval($post['is_shenhe'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}